package com.sunny.framework.system.security.service;

import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.google.common.collect.Maps;
import com.sunny.framework.system.entity.User;

/**
 * 更高效的AccountService实现，基于MyBatis + Memcached的方案，以JSON格式存储Memcached中的内容。
 * 
 * @author calvin
 */
@Component
@Transactional(readOnly = true)
public class AccountEffectiveService {



	/**
	 * 先访问Memcached, 使用JSON字符串存放对象以节约空间.
	 */
	public User getUser(Long id) {
//		String key = MemcachedObjectType.USER.getPrefix() + id;

		User user = null;
//		String jsonString = memcachedClient.get(key);
//
//		if (jsonString == null) {
//			user = userDao.get(id);
//			if (user != null) {
//				jsonString = jsonMapper.toJson(user);
//				memcachedClient.set(key, MemcachedObjectType.USER.getExpiredTime(), jsonString);
//			}
//		} else {
//			user = jsonMapper.fromJson(jsonString, User.class);
//		}
		return user;
	}

	public List<User> searchUser(String loginName, String name) {
		Map<String, Object> parameters = Maps.newHashMap();
		parameters.put("loginName", loginName);
		parameters.put("name", name);
		//return userDao.search(parameters);
		return null;
	}

	@Transactional
	public void saveUser(User user) {
//		userDao.save(user);
	}

	@Transactional
	public void deleteUser(Long id) {
//		userDao.delete(id);
	}
}
